package com.totsp.crossword.net;

import java.io.File;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;

/**
 * Created by Doug on 1/19/14.
 */
public class NYTXPFDownloader extends AbstractXPFDownloader {


    private static final String NAME = "New York Times XPF";
    private final HashMap<String, String> headers = new HashMap<String, String>();
    NumberFormat nf = NumberFormat.getInstance();

    public NYTXPFDownloader() {
        super(
                "http://www.xwordinfo.com/xml/Puzzles/2014/",
                DOWNLOAD_DIR, NAME);
        nf.setMinimumIntegerDigits(2);
        nf.setMaximumFractionDigits(0);
        headers.put("Accept","*/*");
        headers.put("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
        headers.put("Accept-Language", "en-US,en;q=0.8");
        headers.put("Connection", "keep-alive");
        headers.put("Content-Length", "0");

    }

    public int[] getDownloadDates() {
        return NYTXPFDownloader.DATE_DAILY;

    }

    public String getName() {
        return NAME;
    }

    public File download(Date date) {
        return download(date, this.createUrlSuffix(date), headers);
    }

    @Override
    protected String createUrlSuffix(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("MMMdd-yyyy", Locale.US);
        return sdf.format(date) + ".xml" ;
    }
}
